package com.example.studentsystem;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ListView;

import com.example.studentsystem.bean.UserBean;
import com.example.studentsystem.dao.MyDao;
import com.example.studentsystem.db.MyHelper;

import java.util.ArrayList;
import java.util.List;

public class DengLu extends AppCompatActivity implements View.OnClickListener {
    Button select;
    Button insert;
    List<UserBean> student;
    ListView lv;
    Adapter adapter;
    UserBean userBean;
    AutoCompleteTextView cx;
    List<Integer> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_deng_lu);
        select = findViewById(R.id.select);
        insert = findViewById(R.id.insert);
        lv=findViewById(R.id.lv);
        cx=findViewById(R.id.cx);
        student = new ArrayList<>();
        list=new ArrayList<>();
        userBean=new UserBean();
        MyDao myDao = new MyDao(this);
        //Intent data = getIntent();
        //if(data.getIntExtra("id",-1)!=-1) {
           student=myDao.select(userBean);

        //}
        adapter = new Adapter(this,student,lv);
        lv.setAdapter(adapter);
        insert.setOnClickListener(this);
        select.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        int id  = view.getId();
        Intent intent = new Intent();
        switch (id){
            case R.id.insert:
               intent.setClass(this,INSERT.class);
               startActivity(intent);
               break;
            case R.id.select:
                MyDao myDao = new MyDao(this);
                userBean=new UserBean();
                userBean.setName(cx.getText().toString());
               // cx.setAdapter(new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,));
                student=myDao.select(userBean);
                adapter = new Adapter(this,student,lv);
                lv.setAdapter(adapter);

        }
    }
}